/*     */ package com.zimbra.qa.unittest.server;
/*     */ 
/*     */ import com.zimbra.common.localconfig.KnownKey;
/*     */ import com.zimbra.common.localconfig.LC;
/*     */ import com.zimbra.cs.mailbox.Document;
/*     */ import com.zimbra.cs.mailbox.MailItem;
/*     */ import com.zimbra.cs.mailbox.MailItem.Type;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.cs.mailbox.WikiItem;
/*     */ import com.zimbra.cs.mime.ParsedDocument;
/*     */ import com.zimbra.cs.store.Blob;
/*     */ import com.zimbra.cs.store.MailboxBlob;
/*     */ import com.zimbra.cs.store.StoreManager;
/*     */ import com.zimbra.cs.volume.Volume;
/*     */ import com.zimbra.cs.volume.Volume.Builder;
/*     */ import com.zimbra.cs.volume.VolumeManager;
/*     */ import com.zimbra.qa.unittest.TestUtil;
/*     */ import java.io.ByteArrayInputStream;
/*     */ import java.io.File;
/*     */ import java.util.List;
/*     */ import junit.framework.TestCase;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public final class TestDocumentServer
/*     */   extends TestCase
/*     */ {
/*  39 */   private static final String NAME_PREFIX = TestDocumentServer.class.getSimpleName();
/*     */   private static final String USER_NAME = "user1";
/*     */   private long mOriginalCompressionThreshold;
/*     */   private boolean mOriginalCompressBlobs;
/*     */   
/*     */   public void setUp()
/*     */     throws Exception
/*     */   {
/*  47 */     cleanUp();
/*     */     
/*  49 */     Volume vol = VolumeManager.getInstance().getCurrentMessageVolume();
/*  50 */     this.mOriginalCompressBlobs = vol.isCompressBlobs();
/*  51 */     this.mOriginalCompressionThreshold = vol.getCompressionThreshold();
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   public void testDeleteRevisions()
/*     */     throws Exception
/*     */   {
/*  60 */     Mailbox mbox = TestUtil.getMailbox("user1");
/*     */     
/*     */ 
/*  63 */     String content = "one";
/*  64 */     ParsedDocument pd = new ParsedDocument(new ByteArrayInputStream(content.getBytes()), NAME_PREFIX + "-testDeleteRevisions.txt", "text/plain", System.currentTimeMillis(), "user1", "one", true);
/*     */     
/*  66 */     Document doc = mbox.createDocument(null, 16, pd, MailItem.Type.DOCUMENT, 0);
/*  67 */     int docId = doc.getId();
/*  68 */     MailItem.Type type = doc.getType();
/*  69 */     File blobDir = getBlobDir(doc);
/*  70 */     List<Document> revisions = mbox.getAllRevisions(null, docId, type);
/*  71 */     assertEquals(1, revisions.size());
/*  72 */     if (TestUtil.checkLocalBlobs()) {
/*  73 */       assertEquals(1, getBlobCount(blobDir, docId));
/*     */     }
/*  75 */     assertEquals(true, doc.isDescriptionEnabled());
/*     */     
/*     */ 
/*  78 */     content = "two";
/*  79 */     pd = new ParsedDocument(new ByteArrayInputStream(content.getBytes()), NAME_PREFIX + "-testDeleteRevisions2.txt", "text/plain", System.currentTimeMillis(), "user1", "two", false);
/*     */     
/*  81 */     doc = mbox.addDocumentRevision(null, docId, pd);
/*  82 */     assertEquals(2, mbox.getAllRevisions(null, docId, type).size());
/*  83 */     if (TestUtil.checkLocalBlobs()) {
/*  84 */       assertEquals(2, getBlobCount(blobDir, docId));
/*     */     }
/*  86 */     assertEquals(false, doc.isDescriptionEnabled());
/*     */     
/*     */ 
/*  89 */     mbox.move(null, doc.getId(), doc.getType(), 3);
/*  90 */     mbox.emptyFolder(null, 3, false);
/*  91 */     mbox.emptyDumpster(null);
/*  92 */     if (TestUtil.checkLocalBlobs()) {
/*  93 */       assertEquals(0, getBlobCount(blobDir, docId));
/*     */     }
/*     */   }
/*     */   
/*     */   private int getBlobCount(File dir, int id) throws Exception
/*     */   {
/*  99 */     int count = 0;
/* 100 */     String prefix = id + "-";
/* 101 */     for (File file : dir.listFiles()) {
/* 102 */       if (file.getName().startsWith(prefix)) {
/* 103 */         count++;
/*     */       }
/*     */     }
/* 106 */     return count;
/*     */   }
/*     */   
/*     */   private File getBlobDir(Document doc) throws Exception {
/* 110 */     MailboxBlob mblob = StoreManager.getInstance().getMailboxBlob(doc);
/* 111 */     File blobFile = mblob.getLocalBlob().getFile();
/* 112 */     return blobFile.getParentFile();
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public void testCompressedVolume()
/*     */     throws Exception
/*     */   {
/* 122 */     if (LC.documents_disable_instant_parsing.booleanValue() == true)
/* 123 */       return;
/* 124 */     VolumeManager mgr = VolumeManager.getInstance();
/* 125 */     Volume current = mgr.getCurrentMessageVolume();
/* 126 */     mgr.update(Volume.builder(current).setCompressBlobs(true).setCompressionThreshold(1L).build());
/* 127 */     String content = "<wiklet class='TOC' format=\"template\" bodyTemplate=\"_TocBodyTemplate\" itemTemplate=\"_TocItemTemplate\">abc</wiklet>";
/* 128 */     Mailbox mbox = TestUtil.getMailbox("user1");
/* 129 */     WikiItem wiki = mbox.createWiki(null, 16, NAME_PREFIX + "-testCompressedVolume", "Unit Test", null, new ByteArrayInputStream(content.getBytes()));
/*     */     
/* 131 */     assertEquals("abc", wiki.getFragment());
/*     */   }
/*     */   
/*     */   public void tearDown() throws Exception
/*     */   {
/* 136 */     cleanUp();
/*     */   }
/*     */   
/*     */   private void cleanUp() throws Exception {
/* 140 */     TestUtil.deleteTestData("user1", NAME_PREFIX);
/*     */     
/*     */ 
/* 143 */     Mailbox mbox = TestUtil.getMailbox("user1");
/* 144 */     for (MailItem item : mbox.getItemList(null, MailItem.Type.DOCUMENT)) {
/* 145 */       if (item.getName().contains(NAME_PREFIX)) {
/* 146 */         mbox.delete(null, item.getId(), item.getType());
/*     */       }
/*     */     }
/*     */     
/*     */ 
/* 151 */     VolumeManager mgr = VolumeManager.getInstance();
/* 152 */     Volume current = mgr.getCurrentMessageVolume();
/* 153 */     Volume vol = Volume.builder(current).setCompressBlobs(this.mOriginalCompressBlobs).setCompressionThreshold(this.mOriginalCompressionThreshold).build();
/*     */     
/*     */ 
/* 156 */     mgr.update(vol);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/server/TestDocumentServer.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */